<?php

/*
 * Cu acest fisier returnez toate mesajele scrise de un utilizator de la ultima actualizare
 */

include_once "funct.php";

if (!isset($_POST["id"], $_POST["ceas"], $_SESSION["user"]))
	iesire();
clean($_POST["id"]);
clean($_POST["ceas"]);
$room = room($_POST["id"]);
if ($room === false)
	echo "-1";
elseif (strtotime($room["end"]) <= strtotime(ceas())) {
	mysql_query("update " . $db["rooms"] . " set terminat='1' where id='" . $room["id"] . "'");
	echo "-1";
} elseif ($room["terminat"] == 1)
	echo "-1";
elseif ($room["intrat"] == 1 && $_SESSION["user"] == $room["user"]) {
	mysql_query("update " . $db["rooms"] . " set intrat='2' where id='" . $room["id"] . "'");
	echo "1";
} else {
	$continut = "";
	$rezultat = mysql_query("select * from " . $db["messages"] . " where room='" . $_POST["id"] . "' and date>'" . $_POST["ceas"] . "'");
	if (mysql_num_rows($rezultat) > 0) {
		while ($rand = mysql_fetch_array($rezultat)) {
			if ($rand["user"] == $_SESSION["user"])
				$class = "stanga";
			else
				$class = "dreapta";
			$continut.='<div class="replica_' . $class . '">' . $rand["content"] . '</div><br/>';
		}
	}
	echo $continut;
}
?>
